package snippets;

import org.eclipse.swt.*;
import org.eclipse.swt.custom.*;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

/*
 * Scroll a widget into view on focus in
 * 
 * For a list of all SWT example snippets see
 * http://www.eclipse.org/swt/snippets/
 * 
 * @since 3.0
 */

public class Snippet188 {
	
public static void main (String [] args) {
	Display display = new Display ();
	Shell shell = new Shell (display);
	shell.setLayout(new GridLayout());
	String[] tasks = { "koko", "pepe", "sisi", "nana" };
	final ScrolledComposite sc = createScrolledComposite(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL, tasks);
	
	shell.setSize(300, 500);
	shell.open ();
	while (!shell.isDisposed ()) {
		if (!display.readAndDispatch ()) display.sleep ();
	}
	display.dispose ();
}
	static ScrolledComposite createScrolledComposite(Composite parent, int style, String[] tasks) {
		final ScrolledComposite sc =  new ScrolledComposite(parent, style);
		sc.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		Composite c = new Composite(sc, SWT.NONE);
		c.setLayout(new GridLayout(1, true));
		for (String task : tasks) {
			GridData gridData = new GridData();
			gridData.horizontalAlignment = org.eclipse.swt.layout.GridData.FILL;
			Button b = new Button(c, SWT.PUSH);
			b.setText(task);
			ImageData data = new ImageData("src/img/fs_nav.png"); 
		    Image image = new Image(parent.getDisplay(), data);
			b.setImage(image);
			b.setLayoutData(gridData);	
		}
		sc.setContent(c);
		sc.setExpandHorizontal(true);
		sc.setExpandVertical(true);
		sc.setMinSize(c.computeSize(SWT.DEFAULT, SWT.DEFAULT));
		sc.setShowFocusedControl(true);
		return sc;
	}

}